[T4Scaffolding.Scaffolder(Description = "Enter a description of MVCApp here")][CmdletBinding()]
param(        
    [string]$Project,
	[string]$Database,
	[string]$ModelType,
	[string]$CodeLanguage,
	[string[]]$TemplateFolders,
	[switch]$Force = $false
)

#Get items for repository & controller
$proj = Get-Project
$dataModelFile = $Database + "Model.edmx"
$dataModelCode = $Database + "Model.Designer.cs"
$fcm = $proj.ProjectItems.Item("Models").ProjectItems.Item($dataModelFile).ProjectItems.Item($dataModelCode).FileCodeModel
$nsp = $fcm.CodeElements | where-object {$_.Kind -eq 5}
$mems = $nsp.Members | where-object {$_.Kind -eq 1}
$mTypes =  $mems | % {$o = $_; $_.Bases} | % {if(($_.Name -eq "EntityObject") -eq $true){$o}} | select-object Name
$dbContext = $Database + "Entities"

#Create controllers and respositories
$mTypes | % { Scaffold Repository -ModelType $_.Name -DbContextType $dbContext }
$mTypes | % { Scaffold Controller $_.Name -ModelType $_.Name -DbContextType $dbContext -Repository -NoChildItems -Force}

#Create jqGrid action and views
$mTypes | % { Scaffold jqGrid $_.Name -ModelType $_.Name }

#Update the Home Page with controller links
Scaffold HomePage -Force